package com.ruoyi.system.util;


import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.aliyun.tea.TeaModel;

import java.net.URLEncoder;

public class WaterMark2 {
    /**
     * <b>description</b> :
     * <p>使用AK&amp;SK初始化账号Client</p>
     * @return Client
     *
     * @throws Exception
     */
    public static com.aliyun.mts20140618.Client createClient() throws Exception {

        com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
                // 必填，请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID。
                .setAccessKeyId("LTAI5t7f21jByr84oQMbuqM2")
                // 必填，请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。
                .setAccessKeySecret("OIg8kwpnoLNgvts7p4QNdeGuABiVxo");
        config.endpoint = "mts.cn-beijing.aliyuncs.com";
        return new com.aliyun.mts20140618.Client(config);
    }
    /**
     * 提交图片水印转码作业
     * @return
     * @throws Exception
     */
    public static void submitImageWaterMarkJobs() throws Exception {
        com.aliyun.mts20140618.Client client = WaterMark2.createClient();
        //构建水印输出配置
        JSONArray waterMarks = new JSONArray();  //水印数组大小上限为4，即同一路输出最多支持4个水印

        //图片水印
        JSONObject imageWaterMarks = new JSONObject();
        imageWaterMarks.put("WaterMarkTemplateId","0ea162db23444cddb99bd6d0e897cb21");
        imageWaterMarks.put("Type","Image");

        //水印图片路径
        JSONObject logoFile = new JSONObject();
        logoFile.put("Bucket","xunli-chaoyangfy");
        logoFile.put("Location","oss-cn-beijing");
        //图片Object可按需替换为png静态图片、png动图(文件后扩展名需为apng)、mov、gif文件，当素材为非静态图片时，文件扩展名需小写
        logoFile.put("Object", URLEncoder.encode("sy.png", "utf-8"));

        imageWaterMarks.put("InputFile",logoFile.toJSONString());
        waterMarks.add(imageWaterMarks);
        com.aliyun.mts20140618.models.SubmitJobsRequest submitJobsRequest = new com.aliyun.mts20140618.models.SubmitJobsRequest()
                //作业输入
                .setInput("{\"Bucket\":\"xunli-chaoyangfy\",\"Location\":\"oss-cn-beijing\",\"Object\":\"chaoyangfy20250711%2F影音%2FCYFY202108549.mp4\"}")
                //作业输出配置
                .setOutputs("[{\"OutputObject\":\"chaoyangfy20250711%2Fmp4%2FCYFY202108549.mp4\",\"TemplateId\":\"53d65b52587d4343a43851f4101e7e25\",\"WaterMarks\":" + waterMarks.toJSONString() + "}]")

                //输出文件所在的OSS Bucket
                .setOutputBucket("xunli-chaoyangfy")
                //输出文件所在的 OSS Bucket 的地域（OSS Region）
                .setOutputLocation("oss-cn-beijing")
                //管道ID
                .setPipelineId("cb90ed0234c54a2a95fdb4b95def1256");
        com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
            // 复制代码运行请自行打印 API 的返回值
        com.aliyun.mts20140618.models.SubmitJobsResponse resp = client.submitJobsWithOptions(submitJobsRequest, runtime);
        com.aliyun.teaconsole.Client.log(com.aliyun.teautil.Common.toJSONString(TeaModel.buildMap(resp)));

    }

    public static void main(String[] args_) throws Exception {

        //提交图片水印任务
        WaterMark2.submitImageWaterMarkJobs();

    }
}
